<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="Content-Script-Type" content="text/javascript" />
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<title>コントロールパネル</title>
		<link rel="stylesheet" href="./assets/styles/default.css" type="text/css" />
		<link rel="stylesheet" href="./assets/styles/ui-lightness/ui.all.css" type="text/css" />
		<link rel="stylesheet" href="./assets/styles/ui-lightness/jquery-ui-1.7.3.custom.css" type="text/css" />
		<link rel="stylesheet" href="./assets/styles/dialog.css" type="text/css" />
		<style type="text/css">
			input.btnleft{	text-align:	left;};
			.disp{border:0px;border-style:none;background-color:#99CCFF;}
			table.formTable tr {height:38px;}
			td  {height:30px;}
			.errmsg{color:red;width:100%;};
			.all_div {
			  width:100%;
			  float: left;  /* 左方向にフロート */
			  position:relative;
			}
			/* 左カラム固定・右カラム可変 */
			.l_div {
			  width:49.5%;
			  float: left;  /* 左方向にフロート */
			}
			.r_div {
			 /*float: right;  右方向にフロート*/
			  width:50%;
			  z-index:300;
			  overflow-x:auto;
			  overflow-y:hidden;
			}
 		</style>
		<script src="assets/scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
		<script src="assets/scripts/jquery-ui-1.7.3.custom.min.js" type="text/javascript"></script>
		<script src="assets/scripts/ui/ui.dialog.js" type="text/javascript"></script>
		<script src="assets/scripts/menu.js" type="text/javascript"></script>
		<script src="assets/scripts/table.js" type="text/javascript"></script>
		<script type="text/javascript" src="./assets/scripts/jquery.tablefix_1.0.1.js"></script>
		<script type="text/javascript" src="./assets/scripts/tiny_mce/tiny_mce.js"></script>
		<script type="text/javascript" src="./assets/scripts/editor.js"></script>
		<script type="text/javascript" src="./assets/scripts/ui/ui.datepicker.js"></script>
		<script type="text/javascript" src="./assets/scripts/ui/ui.core.js"></script>
		<script type="text/javascript" src="./assets/scripts/searchpara.js"></script>
		<script type="text/javascript">

		var reSetChks = function(obj,index, ntext) {
			var names = document.getElementsByName('pper[]');
			$(names).each(function(i){
				if($(this).attr('id') == obj){
					var p = $(this).closest('tr');
					$('.nums',p).val(ntext);
					$('td',p).each(function(){
						var i = $(this);
						if($('.cp',i).attr('checked')){
							$('.tdtext',i).val(ntext);
						}
					});
				}
			});
		}

		var reSetChks2 = function(obj,index, ntext) {
			var p = $(obj).parent().parent();
			$('td',p).each(function(){
				var i = $(this);
				if($('.cp',i).attr('checked')){
					$('.tdtext',i).val(ntext);
				}
			});
		}

		var reSetChks3 = function(obj,index, ntext,one) {

			var names = document.getElementsByName('pnums[]');
			$(names).each(function(i){
				if($(this).attr('id') == obj){
					var p = $(this).closest('tr');
					$('.per',p).val(one);
					$('td',p).each(function(){
						var i = $(this);
						if($('.cp',i).attr('checked')){
							$('.tdtext',i).val(ntext);
						}
					});
				}
			});
		}

		$(function() {

			var fixWidth = $('.wrapper').width()+13;

			if($('input[name=shop_name]').val() != ""){
				$('#search_result').tablefix({width:fixWidth, height: 560, fixRows: 1, fixCols: 8});
			}

			$(window).resize(function(){
				var ele1 = $("#tableWrapper > div");
				var ele2 = $('> div:first',ele1);
				var ele3 = $('> div:nth-child(2n)',ele1);
				fixWidth = $('.wrapper').width()+13;
				ele1.width(fixWidth);
				ele3.width(fixWidth-ele2.width())
			})

			$('.message').fadeIn("slow");
			$('.text_date').datepicker({
				changeMonth: true,
				changeYear: true,
				dateFormat: 'yy/mm/dd'
			});
			$('#btn-save').click(function(){
				if( confirm('更新してよろしいですか？') ){
					document.fr.submit();
				}
			});
			$('#btn-reset').click(function(){
				location.href = document.fm.action;
			});

			$('#btn_search').click(function(){
				if (chkMustInput()) {
					document.fm.csv.value="";
					document.fm.submit();
				}
			});

			$('.btn_search').click(function(){
				var theValue = "";
				var urlPara = makeSearchURL( this.id, theValue );
				if (urlPara){
					$("#dialog").load( urlPara ).dialog({
						modal:true
						});
					$('#dialog').dialog('open');
				}
			});

			$('#year4').change(function(){
				var year4 = this.value;
				var myDate = new Date();
				var nowtime =  myDate.getTime();
				$.get("mmap_week_ajax.php",{ y: year4,t : nowtime }, function(data){
					$("#matrix_cd").children().remove();
					$("#matrix_cd").append( data );
				});
			});

			$('#zone_cd').change(function(){
				refreshArea(this.value);

			});
			$('#block_cd').change(function(){
				var block = this.value;
				var myDate = new Date();
				var nowtime =  myDate.getTime();

				$.get("ajax_zone_user.php",{ b: block,t : nowtime }, function(data){
					$("#zone_cd").children().remove();
					$("#zone_cd").append( data );
					var zonecd = $("#zone_cd").val() ;
					if(zonecd){
						if (zonecd.length>0){
							refreshArea(zonecd);
						} else {
							$("#area_cd").children().remove();
						}
					}else {
						$("#area_cd").children().remove();
					}
				});
			});

			$('#btn_set').click(function(){
				var  media_name =  ($('#fmset [name^=media_name]').val());
				var  precent    = Number($('#fmset [name^=percent]').val());
				if (media_name == "") {
					alert("媒体名を入力してください！");
					$('#fmset [name^=media_name]').focus();
					return ;
				}
				var   reg=/^\d+$/g;
				if(reg.test(precent)==false)
				{
					alert("パーセントに数字を入力してください");
					$('#fmset [name^=percent]').focus();
					return ;
				}
				var names = document.getElementsByName('media_name[]');
				$(names).each(function(i){
					if(media_name == $(this).val()){
						var p = $(this).closest('tr');
						$('.per',p).val(precent);
						var text =   Math.round(   Number($('input[type=hidden]:eq(1)',p).val())   * precent * 1 /100 ) ;
						 $('.nums:eq(0)',p).val(text);
						reSetChks2($(this),i, text);
					}
				});
			});
			$(".cp").click(function() {
				var isChecked = $(this).attr("checked");
				var idstr = $(this).attr("id");
				var valid = $(this).val();
				var index =  idstr.split("_")[1] ;
				if (isChecked) {
					var text =  $('#pn_' + index ).attr("value");
					$('#p' + valid + '_' + index ).attr("value", text);
				} else {
					$('#p' + valid + '_' + index ).attr("value", "");
				}
			});

			$(".per").live('change',function(){
				var p = $(this).closest('tr');
				var thePer =  $(this).val();
				var index =  $('#fr [name^=pper]').index($(this));
				var text =   Math.round(   Number($('input[type=hidden]:eq(1)',p).val())   * thePer * 1 /100 ) ;
				$('#pn_' + index ).attr("value", text);
				reSetChks($(this).attr('id'),index, text);
			});

			$(".nums").live('change',function(){
				var p = $(this).closest('tr');
				var one = Number($('input[type=hidden]:eq(1)',p).val());
				var theNum =  Number($(this).val());
				var per = Math.round((theNum/one)*100);
				var index =  $('#fr [name^=pnums]').index($(this));
				reSetChks3($(this).attr('id'),index, theNum,per);
			});

			$(".bs").click(function() {
				var theid = $(this).attr("id") ;
				var idarr =  theid.split("_") ;

				openwinX(idarr[1]);
			});

			$('.sort').change(function(){
				if (this.value == 2) {
					$('#tr_op3')['hide']();
					$('#tr_op2')['show']();
				}else if (this.value == 3) {
					$('#tr_op2')['hide']();
					$('#tr_op3')['show']();
				}else {
					$('#tr_op2')['hide']();
					$('#tr_op3')['hide']();
				}
			});

			//if loader is exist
			$('#loader').remove();

		});
		function refreshArea( zone ){
			var myDate = new Date();
			var nowtime =  myDate.getTime();
			$.get("ajax_area_user.php",{ zo: zone,t : nowtime }, function(data){
				$("#area_cd").children().remove();
				$("#area_cd").append( data );
			});
		}
		function openwinX(inid){
			var strUrl = "tpattern_info.php?pre={{$pre_matrix}}&id=" + inid;
			var myWindow =window.open (strUrl, 'pinf', 'menubar=no,location=no, status=no,toolbar=no,scrollbars=no,resizable=yes,left=0px,top=0px,height=768px, width=280px');
			myWindow.focus();
		}
		function toPage(thepage) {
			document.fm.page.value =  thepage;
			document.fm.csv.value="";
			document.fm.submit();
		}
		function setSS( valcd, valnm ) {
			if (gPara == "shop") {
				document.fm.shop_cd.value = valcd;
				document.fm.shop_name.value = valnm;
			}
			if (gPara == "mediaid") {
				document.fmset.media_cd.value = valcd;
				document.fmset.media_name.value = valnm;
			}
			if (gPara == "smediaid") {
				document.fm.smedia_cd.value = valcd;
				document.fm.smedia_name.value = valnm;
			}
			$('#dialog').dialog("close");
		}
		function heightResize (){
			var l_th_height = $('.l_div th').height();
			$('.r_div th').css('height',l_th_height+'px');
		}
		$(window).resize(heightResize);

		function chkWeek() {
			var weekid = $("#matrix_cd").val() ;
			if (weekid.length == 0){
				alert("週を選択してください");
				return false;
			 }
			return true;
		}

		function chkMustInput() {
			var weekid = $("#matrix_cd").val() ;
			if (weekid.length == 0){
				alert("週を選択してください");
				return false;
			 }

			var blockcd = $("#block_cd").val() ;
			if (blockcd.length == 0){
				alert("ブロックを選択してください");
				return false;
			 }
			return true;
		}

		function makeSearchURL(inval, innameval) {
			//inval -> media,delive, shop
			var sphp = "mserach_simple.php";

			var para = inval.split("_");
			gPara = inval;
			var tpara = inval;
			//alert(para[0]);
			var blockcd = $("#block_cd").val() ;
			if (blockcd.length == 0){
				alert("ブロックを選択してください");
				return false;
			 }
			var zonecd = $("#zone_cd").val() ;

			var areacd = $("#area_cd").val() ;
			if  (tpara  == "shop") {
				sphp = "mserach_shop.php";
			}

			/*
			if (inval.substr(0,5)  == "lnews") {
				tpara = "mediaid";
			}
			 */

			var urlPara = sphp + "?t=" + tpara ;
			urlPara = urlPara + "&v=" + encodeURI(innameval);
			urlPara = urlPara + "&b=" + blockcd;
			urlPara = urlPara + "&z=" + zonecd;
			urlPara = urlPara + "&a=" + areacd;

			var myDate = new Date();
			urlPara = urlPara + "&s=" + myDate.getTime();
			return urlPara;
		}

		</script>
		<link rel="stylesheet" type="text/css" href="./assets/styles/tablesorter.css" />
		<script type="text/javascript" src="./assets/scripts/tablesorter.js"></script>
	</head>
	<body id="">
{{$menu}}
{{$logout}}
		<div id="container"><div class="wrapper">
			<h2>パターン管理</h2>
			<ul class="submenu clearfix">
				<li>店別配布明細検索．更新</li>
				<li><a href="tpattern_copy.php">店別配布明細登録</a></li>
				<li><a href="tpattern_export.php">店別配布明細出力</a></li>
				<li><a href="tpattern_shop.php">店別パターン部数ＤＬ</a></li>
				{{ if !($isG2_3) }} <li><a href="tpattern_delive.php">分納明細出力</a></li> {{/if}}
			</ul>
			<h3>店別配布明細</h3>
			<form name="fm" id="fm" method="get" action="tpattern_index.php" >
				<input type="hidden" name="page" />
				<table class="formTable searchTable">
					<tbody>
					<tr>
						<th><span>※</span>年度.週</th><td>
{{ html_options id='year4' name='year4' options=$year4 selected=$forms.year4 }} 年{{ $err.year4 }}&nbsp;&nbsp;&nbsp;
{{ html_options id='matrix_cd' name='matrix_cd' options=$week  selected=$forms.matrix_cd }}
						</td>
							<th><span>※</span>ブロック</th>
							<td>
{{ html_options id='block_cd' name='block_cd' options=$block selected=$forms.block_cd }}
							</td>
						</tr>
						<tr>
<th><span>※</span>AJA名</th>
<td><!--  {{ html_radios  name='sort' class="sort" options=$sorts selected=$forms.sort separator='&nbsp;' }}&nbsp;
<span id="tr_op2"  style="display:{{if ($forms.sort == 2) }}block{{ else }}none{{ /if}};">
{{ html_options id="area_cd" name='area_cd' options=$areauser selected=$forms.area_cd }}{{ $err.area_cd }}</span>
<span id="tr_op3"  style="display:{{if ($forms.sort == 3) }}block{{ else }}none{{ /if}};">
{{ html_options id='zone_cd' name='zone_cd'  options=$zoneuser selected=$forms.zone_cd }}{{ $err.zone_cd }}</span>-->
ゾーン {{ html_options id='zone_cd' name='zone_cd'  options=$zoneuser selected=$forms.zone_cd }}{{ $err.zone_cd }}
&nbsp;&nbsp;&nbsp;&nbsp;エリア {{ html_options id="area_cd" name='area_cd' options=$areauser selected=$forms.area_cd }}{{ $err.area_cd }}
 </td><th>店舗</th>
							<td>
								<input type="text" name="shop_name" value="{{ $forms.shop_name }}" class="text" readonly/>
								<input type="hidden" name="shop_cd"  value="{{ $forms.shop_cd|escape }}" />
								<button type="button" id="shop" class="btn_search" rel="shop"><span>参照</span></button>
								<button type="button" id="shop_c" class = "btn_clear" rel="shop"><span>クリア</span></button>
							</td>
						</tr>
						<tr>
							<th>媒体</th>
							<td>
								<input type="text" name="smedia_name" class="text" value="{{ $forms.smedia_name }}" readonly />
								<input type="hidden" name="smedia_cd"  value="{{ $forms.smedia_cd }}"  />
								<button type="button" id="smediaid" class="btn_search" rel="smedia"><span>参照</span></button>
								<button type="button" id="smedia_c" class = "btn_clear" rel="smedia"><span>クリア</span></button>
							</td>
							<th>更新日</th>
							<td>
								<input type="text" name="upd_f" class="text_date" value="{{ $forms.upd_f }}" /> ～
								<input type="text" name="upd_t" class="text_date" value="{{ $forms.upd_t }}" />
							</td>
						</tr>
					</tbody>
				</table>
				<p class="button" style="text-align:right">
					<button type="button" id="btn-reset"><span>クリア</span></button>
					<button type="button" id="btn_search" class="submit"><span>絞込検索</span></button>
				</p>
				<input type="hidden" name="search" value="1" />
				<input type="hidden" name="csv" />
			</form>
			<form name="fmset" id="fmset" method="get" action="tpattern_index.php" >
				<input type="hidden" name="page" />
				<table class="formTable searchTable">
					<tbody>
						<tr>
							<th>媒体</th>
							<td>
								<input type="text" name="media_name" class="text" />
								<input type="hidden" name="media_cd" />
								<button type="button" id="mediaid" class="btn_search" rel="media"><span>参照</span></button>
							</td>
							<th>パーセント</th>
							<td>
								<input type="text" name="percent"  class="nper" />
							</td>
							<td class="button"><button type="button" id="btn_set" class="submit"><span>仮設定</span></button></td>
						</tr>
					</tbody>
				</table>
				<input type="hidden" name="search" value="1" />
				<input type="hidden" name="csv" />
			</form>
<form name="fr" id="fr"  action="tpattern_index_save.php" method="post">
	{{ if is_numeric($page.cnt) }}
	{{ if $page.cnt > 0 }}
	{{ if $msg }}
				<p class="message">{{ $msg }}</p>
				{{ if ($errmsg) }}
				<p class="error">{{ $errmsg }}</p>
				{{ /if }}
	{{ else  }}
				<p class="message">{{ $page.cnt }}件の情報が見つかりました。</p>
				<div id="loader"><p>loading</p></div>
	{{ /if }}
			<div id="tableWrapper">
				<table id="search_result" class="sortable" style="table-layout:fixed;word-wrap:break-word;word-break;break-all;">
					<thead>
						<tr>
						<th style="width:38px"><h3>データ<br>参照</h3></th>
							<th style="width:50px"><h3>都道府県</h3></th>
							<th style="width:80px"><h3>媒体</h3></th>
							<th style="width:110px"><h3>納品先</h3></th>
							<th style="width:85px"><h3>販売店<br/>コード</h3></th>
							<th style="width:120px"><h3>販売店エリア</h3></th>
							<th style="width:40px"><h3>部数(％)</h3></th>
							<th style="width:60px"><h3>調整部数</h3></th>
							<th style="width:40px"><h3>店舗<br/>コード</h3></th>
							<th style="width:120px"><h3>店名</h3></th>
							{{ foreach from=$pattern key=kh item=vh name="pattername" }}
								<th  style="width:98px"><h3>{{ $vh.pattern_name }}</h3></th>
							{{ /foreach }}
						<!--
						<th><h3>データ<br>参照</h3></th>
							<th><h3>都道府県</h3></th>
							<th><h3>媒体</h3></th>
							<th><h3>納品先</h3></th>
							<th><h3>販売店<br/>コード</h3></th>
							<th><h3>販売店エリア</h3></th>
							<th><h3>部数(％)</h3></th>
							<th><h3>調整部数</h3></th>
							-->
						</tr>
					</thead>
					<tbody>
				{{ foreach from=$data key=k item=v name="member" }}
				<tr class="{{cycle values=odd,mod name='member'}}">
					<td><button id="{{ $v.ins_shop_shop_cd}}" type="button" class="bs" >参照</button></td>
					<td> <input name="local_name[]"  type="text"  class="dtext" value="{{ $v.local_name}}" readonly/><input name="ins_shop_shop_cd[]"  type="hidden"   class="text" value="{{ $v.ins_shop_shop_cd}}"/></td>
					<td><input name="media_name[]"  type="text"   class="dtext" value="{{ $v.media_name}}" readonly/></td>
					<td><input name="delive_name[]"  type="text"  class="dtext" value="{{ $v.delive_name}}" readonly/></td>
					<td><input name="ins_shop_cd[]"  type="text"  class="dtext" value="{{ $v.ins_shop_cd}}" readonly/><input  id="inum_{{$k}}" name="insert_conums[]"  type="hidden"   class="text" value="{{ $v.insert_conums}}"/></td>
					<td><input name="ins_shop_name[]" type="text"  class="dtext" value="{{ $v.ins_shop_name}}" readonly/></td>
					<td><input id="pp_{{$k}}" name="pper[]"  type="text"  class="tdtext per" style="width:98%" value="{{ $v.pper}}" /></td>
					<td><input id="pn_{{$k}}"name="pnums[]" type="text"  class="tdtext nums" style="width:98%" value="{{ $v.pnums}}" /></td>
					<td><input name="shop_cd[]"   type="text"   class="dtext" value="{{ $v.shop_cd}}" readonly/></td>
					<td><input name="shop_name[]"  type="text"   class="dtext" value="{{ $v.shop_name}}" readonly/></td>
					{{ foreach from=$pattern key=kh item=vh name="pattername" }}
						<td> <input id="c{{ $vh.pattern_cd }}_{{$k}}" name="c{{ $vh.pattern_cd }}[]" type="checkbox" class="cp" value="{{ $vh.pattern_cd }}" {{ if $v[$vh.col] }}checked{{ /if }}/> <input id="p{{ $vh.pattern_cd }}_{{$k}}" name="p{{ $vh.pattern_cd }}[]"  type="text"    class="tdtext" style="width:68%"   value="{{ $v[$vh.col] }}" /></td>
					{{ /foreach }}
				</tr>
				{{ /foreach }}
					</tbody>
				</table>
			</div>
				<p class="button">
					<button type="button" id="btn-save"  ><span>この内容で保存</span></button>
				</p>
{{ else }}
<p class="message">条件にマッチする情報は見つかりませんでした。</p>
{{ /if }}
{{ else }}
	<p class="message">ここに検索結果が表示されます。</p>
{{ /if }}

</form>

<div id="dialog" >
</div>
		</div></div>
		{{ $footer }}
	</body>
</html>